package com.justech.eat.service.component.impl;

import com.justech.common.util.MesAssert;
import com.justech.eat.entity.Order;
import com.justech.eat.entity.OrderDetail;
import com.justech.eat.model.SettlementResult;
import com.justech.eat.service.component.OrderDetailAfterSettlementProcessor;
import org.springframework.stereotype.Component;

/**
 * @program: eat-service
 * @description: 处理吃霸王餐的情况
 * @author: feifei.li
 * @create: 2020-06-11 12:25
 **/
@Component(value = "overlordMealProcessor")
public class OverlordMealProcessor extends AbstractOrderDetailAfterSettlementProcessor implements OrderDetailAfterSettlementProcessor {
    @Override
    public void afterSettlement(SettlementResult s) {
        if (s.getJobNumber() == null) {
            throw new RuntimeException("系统中无法获取该用户工号，无法进行下一步操作");
        }
        OrderDetail orderDetail = orderDetailService.getOrderDetail(s.getDate(), s.getJobNumber(), s.getType());
        if (orderDetail == null) {
            Order order = orderBookSubmit.submit(s.getDate(), s.getJobNumber(), 0, 0, 0, 0);
            orderDetail = listToMap(order.getOrderDetails()).get(s.getType());
        }
        if (orderDetail != null) {
            orderDetailAbnormalService.add(orderDetail.getOrderId(), orderDetail.getId(), s.getJobNumber(), 2);
        } else {
            MesAssert.throwBizException("自动填充报餐记录时出现异常");
        }
    }
}
